﻿using System;
using System.Configuration;
using System.Xml;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// Boolean类型内容元素
    /// </summary>
    public sealed class BooleanContentElement : ConfigurationElement
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public BooleanContentElement()
        {
            this.Value = false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="serializeCollectionKey"></param>
        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {            
            this.Value = reader.ReadElementContentAsBoolean();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="serializeCollectionKey"></param>
        /// <returns></returns>
        protected override bool SerializeElement(XmlWriter writer, bool serializeCollectionKey)
        {
            if (writer != null)
            {
                writer.WriteValue(this.Value);
            }
            return true;
        }

        /// <summary>
        /// 值
        /// </summary>
        [ConfigurationProperty("data")]
        public bool Value
        {
            get
            {
                return (bool)this["data"];
            }
            set
            {
                this["data"] = value;
            }
        }
    }
}
